/*
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-04-29 13:44:18
 */
export let ajax={
    post : function(url,data,callback){
        let xhr=new XMLHttpRequest();
        let str
        if(data==null){
            xhr.open('post',url);
            xhr.send()
        }else{
        str=Object.keys(data).map(item=>`${item}=${data[item]}`).join('&');
        xhr.open('post',url);
        xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        xhr.send(str)
        }
        xhr.responseType='json';
        xhr.onreadystatechange=function(){
            if(xhr.readyState===4){
                if(xhr.status===200){
                    callback(xhr.response);
                    
                }
            }
        }
    },
    get: function(url,data,callback){
        let xhr=new XMLHttpRequest();
        
        let str=Object.keys(data).map(item=>`${item}=${data[item]}`).join('&');
        xhr.open('get',url+'?'+str);
        xhr.send();
        xhr.responseType='json';
        xhr.onreadystatechange=function(){
            if(xhr.readyState===4){
                if(xhr.status===200){
                    callback(xhr.response);
                }
            }
        }
    }
}
